﻿using AutoMapper;
using B.S.Warehouse.Domain;
using B.S.Warehouse.ErrorCord;
using B.S.Warehouse.Read.Api.Application.Command.StockInDetailCommand;
using MediatR;
using SqlSugar;

namespace B.S.Warehouse.Read.Api.Application.Handelr.StockInDetailHandler
{
    public class GetStockInDetailHandler : IRequestHandler<GetStockInDetailCommand, ApiResult<List<StockInDetailS>>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public GetStockInDetailHandler(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }
        public async Task<ApiResult<List<StockInDetailS>>> Handle(GetStockInDetailCommand request, CancellationToken cancellationToken)
        {

            ApiResult<List<StockInDetailS>> result = new ApiResult<List<StockInDetailS>>();

            var list = await db.Queryable<StockInDetailS>().ToListAsync();
            result.data = list;
            if (result.data != null)
            {
                result.Code = ApiEnum.显示成功;
                result.MAG = ApiEnum.显示成功.ToString();
            }
            else
            {
                result.Code = ApiEnum.显示成功;
                result.MAG = ApiEnum.显示成功.ToString();
            }

            return result;
        }
    }
}
